package com.zrrd.mapper;

import com.zrrd.pojo.Student;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author WanJl
 * @version 1.0
 * @title StudentMapper
 * @description
 * @create 2024/1/23 17:04
 */
public interface StudentMapper {
    @Select("SELECT * FROM jms2301_db02.student WHERE cid=#{cid}")
    List<Student> selectByCid(Integer cid);

    @Select("SELECT s.id sid, s.name sname, s.age sage " +
            "FROM jms2301_db02.student s, jms2301_db02.stu_cr scc WHERE scc.sid=s.id")
    @Results(value = {
            @Result(column = "sid", property = "id"),
            @Result(column = "sname", property = "name"),
            @Result(column = "sage", property = "age"),
            @Result(
                    column = "sid", //被包含对象的变量名称
                    javaType = List.class,   //被包含对象实际数据类型
                    property = "courseList", //根据查询出来的学生表里的sid查询课程表信息
                    // 调用课程mapper里面的根据sid查询课程的方法
                    many = @Many(select = "com.zrrd.mapper.CourseMapper.selectByStuId")
            )
    })
    List<Student> selectStudentAndCourse();
}
